#Region " Imports "

Imports BlazeApps.Library.News
Imports System.Data

#End Region

Partial Class Usercontrols_News_NewsList
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "

    Private Enum NewsView
        List = 0
        View = 1
    End Enum

    Protected Property NewsGuid() As Guid
        Get
            Return GetGuidFromVS("NewsGuid")
        End Get
        Set(ByVal value As Guid)
            ViewState.Add("NewsGuid", value)
        End Set
    End Property

    Public Property sortCriteria() As String
        Get
            Return CStr(ViewState("sortCriteria"))
        End Get

        Set(ByVal Value As String)
            ViewState("sortCriteria") = Value
        End Set
    End Property

    Public Property sortDir() As String
        Get
            Return CStr(ViewState("sortDir"))
        End Get

        Set(ByVal Value As String)
            ViewState("sortDir") = Value
        End Set
    End Property

#End Region

#Region " Page Events "

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Me.Page.IsPostBack = False Then

            'Set Default Sort Order and Direction
            Me.sortCriteria = "createdate"
            Me.sortDir = "desc"

            LoadNewsList()

        End If

    End Sub

#End Region

#Region " Save Data "

#End Region

#Region " Load Data "

	Private Sub LoadNewsList()
		Dim List As New NewsList
		Dim DT As New DataTable
		Dim DV As New DataView

		DV.Table = List.GetNews()

		DV.Sort = Me.sortCriteria & " " & Me.sortDir

		With Me.uxNewsRepeater
			.DataSource = DV
			.DataBind()
		End With

		'SetMultiViewIndex(NewsView.List)

	End Sub

#End Region

#Region " Form Controls Events "

	Protected Sub EditNews(ByVal sender As Object, ByVal e As CommandEventArgs)
		Response.Redirect(String.Format("{0}.aspx?pid=news_addnews&id={1}", AppPage, ConvertToGuid(e.CommandArgument.ToString)))
	End Sub

	Protected Sub uxNewsRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles uxNewsRepeater.ItemDataBound
		If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
			Dim CPE As AjaxControlToolkit.CollapsiblePanelExtender = e.Item.FindControl("uxNewsCollapsiblePanelExtender")

			CPE.CollapsedImage = String.Format("~/App_Themes/{0}/images/icons/collapse.gif", Page.Theme.ToString.Trim)
			CPE.ExpandedImage = String.Format("~/App_Themes/{0}/images/icons/expand.gif", Page.Theme.ToString.Trim)

		End If
	End Sub

#End Region

#Region " Helpers and Methods "

	'Private Sub SetMultiViewIndex(ByVal Index As NewsView)
	'    Me.uxNewsMultiview.ActiveViewIndex = Index
	'End Sub

#End Region

End Class
